package com.SoilMM.controller;


import com.SoilMM.entity.GtimeMonitEntity;
import com.SoilMM.entity.ShiShangEntity;
import com.SoilMM.entity.ShiShangTimeEntity;
import com.SoilMM.mapper.ShiShangMapper;
import com.SoilMM.service.ShiShangService;

import com.SoilMM.service.ShiShangTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gramorgan
 * @since 2021-07-03
 */
@RestController
@RequestMapping("/shiShangEntity")
public class ShiShangController {
    @Autowired
    private ShiShangService shiShangService;
//    ShiShangTimeEntity shiShangTimeEntity=new ShiShangTimeEntity();
//    private ShiShangTimeService shiShangTimeService;
    @RequestMapping("/shidata")
    public Map<String,Object>list() {
        Map<String,Object> resultMap = new HashMap<>();
        List<ShiShangEntity> list = shiShangService.list();
//        List list1 = shiShangMapper.listshiShang();
//        System.out.println(list[]);
        List<Object> list1 = new LinkedList<>();
        for(int i=0; i<list.size();i++){
            Map<String,Object> res = new HashMap<>();
            ShiShangEntity data = list.get(i);
            double d = Math.random();
            d = d*10;
            float f = (float)d;
            res.put("name", data.getName());
//            shiShangTimeEntity.setId(4);
//            shiShangTimeEntity.setName(data.getName());
//            shiShangTimeEntity.setValue(data.getValue());
//            shiShangTimeEntity.setTime(LocalDateTime.now());
//            System.out.println(shiShangTimeEntity);
//            shiShangTimeService.save(shiShangTimeEntity);
            res.put("value", data.getValue()+f);
//            shiShangTimeEntity.setValue((data.getValue()+f));
//            shiShangTimeService.updateById(shiShangTimeEntity);
            list1.add(res);
        }
        resultMap.put("code",111);
        resultMap.put("message","查询成功");
        resultMap.put("data", list1);
        return resultMap;
    }


}

